﻿
Partial Class DevTeam_TaskProgress
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim _userID As String
		_userID = Membership.GetUser.ProviderUserKey.ToString

		lClaimOutcome.Visible = False
		lUpdateOutcome.Text = ""

		If Not Page.IsPostBack Then
			FillSupportingDataForUser(_userID)

			ddlFeaturesInSprint.Enabled = False
			ddlUnclaimedTasks.Enabled = False
			bClaimTask.Enabled = False

			ddlPriorities.Enabled = False
			ddlStatus.Enabled = False
			ddlNewDev.Enabled = False
			bUpdateTask.Enabled = False
			tActualTime.Enabled = False

		End If
	End Sub

	Private Sub FillSupportingDataForUser(ByVal sUserId As String)

		Dim _bl As New scrumrBL
		_bl.FillSprintsForUser(sUserId, ddlSprints)
		_bl.FillTasksForUser(sUserId, ddlTaskToUpdate)
		_bl.FillPrioritiesList(ddlPriorities)
		_bl.FillStatusList(3, ddlStatus)
		_bl = Nothing

	End Sub

	Protected Sub ddlSprints_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSprints.SelectedIndexChanged

		Dim _bl As New scrumrBL
		_bl.FillFeaturesInSprint(ddlSprints.SelectedValue, ddlFeaturesInSprint)
		_bl = Nothing
		ddlFeaturesInSprint.Enabled = True
		ddlUnclaimedTasks.Enabled = False
		ddlUnclaimedTasks.Items.Clear()
		bClaimTask.Enabled = False

	End Sub

	Protected Sub ddlFeaturesInSprint_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlFeaturesInSprint.SelectedIndexChanged

		Dim _bl As New scrumrBL
		_bl.FillUnclaimedTasks(ddlUnclaimedTasks, ddlFeaturesInSprint.SelectedValue)
		_bl = Nothing

		If ddlUnclaimedTasks.Items.Count > 1 Then
			ddlUnclaimedTasks.Enabled = True
			bClaimTask.Enabled = True
		End If

		lUpdateOutcome.Text = ""

	End Sub

	Protected Sub bClaimTask_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bClaimTask.Click

		Dim _userID As String
		_userID = Membership.GetUser.ProviderUserKey.ToString
		lClaimOutcome.Visible = True

		Try
			Dim _task As New task
			_task.AssignTaskToUser(_userID, ddlUnclaimedTasks.SelectedValue)
			lClaimOutcome.Text = "Task has been claimed."
			_task = Nothing
		Catch ex As Exception
			lClaimOutcome.Text = ex.Message
		End Try

	End Sub

	Protected Sub ddlTaskToUpdate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlTaskToUpdate.SelectedIndexChanged

		If ddlTaskToUpdate.SelectedValue > 0 Then
			Dim _task As task
			Try
				_task = New task(ddlTaskToUpdate.SelectedValue)

				Dim _bl As New scrumrBL
				_bl.FillNewDev(ddlTaskToUpdate.SelectedValue, ddlNewDev)
				_bl = Nothing

				ddlPriorities.SelectedValue = _task.PriorityID
				ddlStatus.SelectedValue = _task.StatusID
				ddlNewDev.SelectedValue = _task.UserID
				tActualTime.Text = _task.ActualTime

				ddlPriorities.Enabled = True
				ddlStatus.Enabled = True
				ddlNewDev.Enabled = True
				tActualTime.Enabled = True
				bUpdateTask.Enabled = True

			Catch ex As Exception
				lUpdateOutcome.Visible = True
				lUpdateOutcome.Text = ex.Message
			End Try

		Else
			ddlPriorities.Enabled = False
			ddlStatus.Enabled = False
			ddlNewDev.Enabled = False
			bUpdateTask.Enabled = False
			tActualTime.Enabled = False
			lUpdateOutcome.Text = ""
		End If


	End Sub

	Protected Sub bUpdateTask_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bUpdateTask.Click

		lUpdateOutcome.Text = ""

		Try
			Dim _task As New task(ddlTaskToUpdate.SelectedValue)

			_task.StatusID = ddlStatus.SelectedValue
			_task.PriorityID = ddlPriorities.SelectedValue
			_task.ActualTime = tActualTime.Text
			_task.UserID = ddlNewDev.SelectedValue

			_task.UpdateTask()

			lUpdateOutcome.Text = "Task has been updated!"

		Catch ex As Exception
			lUpdateOutcome.Text = ex.Message
		End Try


	End Sub

End Class
